import { Component, OnInit } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { ActivatedRoute } from '@angular/router';
import { from } from 'rxjs';
import { map } from 'rxjs/operators';

import { LogService, OperationType } from '../../services/log.service';
import { AreaConfigDetail } from '../../services/area-config';

@Component({
    selector: 'm-area-config-detail',
    templateUrl: './area-config-detail.component.html',
    styleUrls: ['./area-config-detail.component.scss']
})
export class AreaConfigDetailComponent implements OnInit {
    labelList: string[];
    thList: string[];
    activeLabel = this.labelList[0];

    constructor(private route: ActivatedRoute,
        protected http: HttpClient,
        private service: LogService) { }

    // TODO(jouyouyun): implement
    id = this.route.paramMap.pipe(map(params => params.get("id")));
    result$ = from(this.service.log<AreaConfigDetail>(this.route.snapshot).get(Number(this.id)));

    ngOnInit() {
        this.result$.subscribe(ret => this.initList(ret.operation));
    }

    initList(op: number): void {
        switch (op) {
            case OperationType.HumanChanged:
                this.labelList = ['添加的人员', '删除的人员'];
                this.thList = ['角色', '姓名', '工号', '状态'];
                break;
            case OperationType.PcChanged:
                this.labelList = ['添加的终端', '删除的终端'];
                this.thList = ['终端别名', '终端备注', '系统状态', '状态'];
                break;
            case OperationType.SoftwareChanged:
                this.labelList = ['添加的软件', '删除的软件'];
                this.thList = ['软件别名', '软件备注', '版本', '状态'];
                break;
        }
    }
}
